#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N = 2e5 + 10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int a, b, c;
void solve()
{
    cin >> a >> b >> c;

    int sum1 = abs(a - b) + 1;
    int tt = sum1 + sum1 - 2;
    if(tt % 2 != 0)
    {
        cout << -1 << '\n';
        return;
    }
    else
    {
        int sum2 = tt;
        int mid = (sum2 / 2) + 1;
        if(c>=mid)
        {
            int cur=c-abs(a-b);
            if(cur<0||cur>sum2||c>sum2||a>sum2||b>sum2) cout<<-1<<'\n';
            else cout<<cur<<'\n';
        }
        else
        {
            int cur=c+abs(a-b);
            if(cur<0||cur>sum2||c>sum2||a>sum2||b>sum2) cout<<-1<<'\n';
            else cout<<cur<<'\n';
            
        }
    }


}

int main()
{
    close();
    int T;
    cin >> T;
    while (T--) solve();
    return 0;
}